﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LandandSurvey
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            if (HasPermission())
            {
                lnkHolder.InnerHtml = "<a href='EditAbout.aspx'>Edit</a>";
            }

            landsdbEntities container = new landsdbEntities();
            AboutContent result = (from i in container.AboutContents
                                   select i).ToList().FirstOrDefault();
            if (result != null)
            {
                AboutHolder.InnerHtml = result.Content;
            }
        }

        public bool HasPermission()
        {
            if (Session["user.loggedin"] == null)
            {
                return false;
            }
            if (Session["user.loggedin"].ToString() == "true")
            {
                landsdbEntities container = new landsdbEntities();
                string username = Session["user.name"].ToString();
                AppUser user = (from i in container.AppUsers
                                where i.UserName == username
                                select i).ToList().FirstOrDefault();
                if (user != null)
                {
                    if (user.EditAbout == true)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}
